import os
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    # 应用配置
    DEBUG_MODE: bool
    APP_HOST: str
    APP_PORT: int
    
    # 静态文件目录
    STATIC_DIR: str
    STATIC_URL: str
    STATIC_NAME: str
    
    # 安全配置
    SECRET_KEY: str
    ACCESS_TOKEN_EXPIRE_MINUTES: int
    ALGORITHM: str
    
    # 数据库配置
    MYSQL_HOST: str
    MYSQL_PORT: int
    MYSQL_USER: str
    MYSQL_PASS: str
    MYSQL_DB: str
    
    # Redis配置
    REDIS_HOST: str
    REDIS_PORT: int
    REDIS_PASSWORD: str
    REDIS_DB: int
    REDIS_MAX_CONNECTIONS: int
    
    # 日志配置
    LOG_LEVEL: str
    LOG_FILE: str
    
    # CORS配置
    CORS_ORIGINS: list
    
    # 限流配置
    RATE_LIMIT_ENABLED: bool
    RATE_LIMIT_TIMES: int
    RATE_LIMIT_SECONDS: int
    
    class Config:
        # 根据环境变量动态选择配置文件
        env = os.getenv("ENV", "development")
        if env == "production":
            env_file = ".env.product"
        else:
            env_file = ".env.develop"
        env_file_encoding = "utf-8"


config = Settings()
